<html lang="zh-CN"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="format-detection" content="telephone=no">
<title>全部商品</title>
<link rel="stylesheet" type="text/css" href="../addons/smart_ct/template/css/1/wei_canyin_v1.8.4.css?v=1.1.3" media="all">
<link rel="stylesheet" type="text/css" href="../addons/smart_ct/template/css/1/wei_dialog_v1.2.1.css?v=1.1" media="all">
<link data-turbolinks-track="true" href="{RES}/mobile/diandan/assets/diandanbao/font.css?v=1" media="all" rel="stylesheet">
<style>
    /*解决右边背景总是为灰色的bug*/
    #page_allMenu section article, #pInfo {
        min-height: 100%;
    }
</style>
<script type="text/javascript" src="../addons/smart_ct/template/js/1/wei_webapp_v2_common_v1.9.4.js"></script>
<style>abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,fieldset,figure,figcaption,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,small,time,video,legend{display:block;}</style>
<script type="text/javascript" src="../addons/smart_ct/template/js/1/wei_dialog_v1.9.9.js"></script>
    <script type="text/javascript" src="../addons/smart_ct/template/js/2/jQuery.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=5PESLgvMcSbSUbPjmDKgvGZ3"></script>
    <script type="text/javascript" src="../addons/smart_ct/template/js/postion_detail.js?v=3"></script>
</head>
<body id="page_allMenu">
<style>
    .ddb-nav-header {
        opacity: 0.95;
        position: fixed;
        top: 0;
        width: 100%;
        height: 45px;
        line-height: 44px;
        z-index: 1999;
        border-bottom: 1px solid #eeeeee;
        background-color: white;
        color: #555555
    }

    .ddb-nav-header a {
        color: #555555
    }

    .ddb-nav-header .header-title {
        width: 50%;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-align: center;
        overflow: hidden;
        font-size: 17px;
        font-weight: bold;
        display: inline-block;
        margin-left: 25%
    }

    .ddb-nav-header .nav-left-item, .ddb-nav-header .nav-right-item {
        display: inline-block;
        height: 100%
    }

    .ddb-nav-header .nav-left-item i, .ddb-nav-header .nav-right-item i {
        width: 20px;
        font-size: 18px;
        line-height: inherit;
    }

    .ddb-nav-header .nav-left-item {
        width: 25%;
        float: left;
        padding-left: 10px
    }

    .ddb-nav-header .nav-right-item {
        width: 20%;
        float: right;
        text-align: right
    }

    .ddb-nav-header .nav-right-item .operation-button {
        font-size: 16px;
        text-align: center;
        color: #ef4437;
        font-weight: bold
    }

    .ddb-nav-header .nav-left-item ~ .header-title {
        margin-left: 0
    }

    .ddb-nav-header.label-red {
        border-bottom: 0
    }



    #ddb-branch-index {
        background-color: white;
        color: #777777
    }

    #ddb-branch-index .tag {
        font-size: 12px;
        border-radius: 1px;
        padding: 1px 2px
    }

    #ddb-branch-index .tuans .tuan {
        display: block;
        border: 1px dotted #eeeeee;
        border-radius: 3px;
        font-size: 14px;
        padding: 4px;
        margin: 0 8px 5px 0
    }

    #ddb-branch-index .closed {
        opacity: 0.4
    }

    #ddb-branch-index .branch-item {
        padding-left: 8px;
        border-bottom: 1px solid #eeeeee;
        background-color: white
    }

    #ddb-branch-index .branch-item .branch-info {
        display: block;
        padding: 10px 8px 6px 70px
    }

    #ddb-branch-index .branch-item .branch-image {
        float: left;
        margin-left: -70px;
        width: 70px
    }

    #ddb-branch-index .branch-item .branch-image img {
        width: 100%;
        border: 1px solid #eeeeee;
        border-radius: 2px
    }

    #ddb-branch-index .branch-item .branch-detail-info {
        padding-left: 8px;
        vertical-align: top
    }

    #ddb-branch-index .branch-item .branch-detail-info .first-line, #ddb-branch-index .branch-item .branch-detail-info .second-line, #ddb-branch-index .branch-item .branch-detail-info .third-line {
        width: 100%
    }

    #ddb-branch-index .branch-item .branch-detail-info .first-line {
        height: 24px;
        line-height: 20px;
        padding-bottom: 4px
    }

    #ddb-branch-index .branch-item .branch-detail-info .first-line > div {
        display: inline-block;
        vertical-align: middle
    }

    #ddb-branch-index .branch-item .branch-detail-info .first-line .tag {
        line-height: 14px
    }

    #ddb-branch-index .branch-item .branch-detail-info .first-line .name {
        font-size: 16px;
        color: #333333;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
    }

    #ddb-branch-index .branch-item .branch-detail-info .second-line {
        height: 24px;
        font-size: 12px;
        line-height: 24px
    }

    #ddb-branch-index .branch-item .branch-detail-info .second-line > div {
        display: inline-block
    }

    #ddb-branch-index .branch-item .branch-detail-info .third-line {
        font-size: 12px;
        direction: rtl;
        display: table
    }

    #ddb-branch-index .branch-item .branch-detail-info .third-line > div {
        display: table-cell
    }

    #ddb-branch-index .branch-item .branch-detail-info .third-line .distance {
        width: 60px;
        min-width: 60px
    }

    #ddb-branch-index .branch-item .branch-detail-info .third-line .address {
        width: 100%;
        text-align: left
    }

    #ddb-delivery-branch-index {
        color: #777777;
        background-color: white
    }

    #ddb-delivery-branch-index .closed {
        opacity: 0.4
    }

    #ddb-delivery-branch-index .branch-item {
        padding-left: 8px;
        border-bottom: 1px solid #eeeeee;
        background-color: white
    }

    #ddb-delivery-branch-index .branch-item .branch-info {
        display: block;
        padding: 10px 8px 6px 70px;
        border-bottom: 1px dotted #eeeeee
    }

    #ddb-delivery-branch-index .branch-item .branch-image {
        float: left;
        margin-left: -70px;
        width: 70px;
        min-width: 70px
    }

    #ddb-delivery-branch-index .branch-item .branch-image img {
        width: 100%;
        border: 1px solid #eeeeee;
        border-radius: 2px
    }

    #ddb-delivery-branch-index .branch-item .delivery-info {
        padding-left: 8px;
        vertical-align: top
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line, #ddb-delivery-branch-index .branch-item .delivery-info .second-line, #ddb-delivery-branch-index .branch-item .delivery-info .third-line {
        width: 100%
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line {
        height: 24px;
        line-height: 20px;
        padding-bottom: 4px
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line > div {
        display: inline-block;
        vertical-align: middle
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line .name {
        font-size: 16px;
        color: #333333;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line .tag {
        font-size: 12px;
        line-height: 14px;
        border-radius: 1px;
        padding: 1px 2px
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .first-line .sales {
        font-size: 12px;
        width: 80px;
        float: right;
        text-align: right
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .second-line {
        height: 14px;
        font-size: 12px;
        line-height: 14px
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .second-line > div {
        display: inline-block
    }

    #ddb-delivery-branch-index .branch-item .delivery-info .third-line {
        font-size: 12px
    }

    #ddb-delivery-branch-index .top-sales {
        padding: 6px 8px 6px 0;
        font-size: 12px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis
    }

    #ddb-delivery-branch-index .branch-item-table, #ddb-branch-index .branch-item-table {
        display: table;
        width: 100%
    }

    #ddb-delivery-branch-index .branch-item-table .tags, #ddb-branch-index .branch-item-table .tags {
        float: left;
        margin-left: -5px
    }

    #ddb-delivery-branch-index .branch-item-tr, #ddb-branch-index .branch-item-tr {
        display: table-row
    }

    #ddb-delivery-branch-index .branch-item.block, #ddb-branch-index .branch-item.block {
        display: table-cell;
        margin: 10px 1%;
        width: 31.3%;
        text-align: center;
        padding: 5px;
        border-bottom: 0px
    }

    #ddb-delivery-branch-index .branch-item.block .branch-info, #ddb-branch-index .branch-item.block .branch-info {
        padding: 0
    }

    #ddb-delivery-branch-index .branch-item.block .branch, #ddb-branch-index .branch-item.block .branch {
        width: 100%;
        height: 100px;
        border: solid 1px #ccc;
        padding: 5px
    }

    #ddb-delivery-branch-index .branch-item.block .branch .img, #ddb-branch-index .branch-item.block .branch .img {
        width: 100%;
        height: 100%
    }

    #ddb-delivery-branch-index .branch-item.block .branch .img .cover, #ddb-branch-index .branch-item.block .branch .img .cover {
        width: 100%;
        height: 100%;
        position: relative
    }

    #ddb-delivery-branch-index .branch-item.block .branch .img .cover .label div, #ddb-branch-index .branch-item.block .branch .img .cover .label div {
        display: block;
        width: 18px;
        height: 21px;
        line-height: 21px;
        font-size: 11px;
        text-align: center;
        margin-right: 4px;
        margin-top: -2px;
        float: left
    }

    #ddb-delivery-branch-index .branch-item.block .branch .img .cover .rest, #ddb-branch-index .branch-item.block .branch .img .cover .rest {
        width: 50%;
        float: right
    }

    #ddb-delivery-branch-index .branch-item.block .branch .img .cover .branch_name, #ddb-branch-index .branch-item.block .branch .img .cover .branch_name {
        width: 100%;
        height: 20px;
        position: absolute;
        left: 0;
        bottom: 0;
        text-align: center;
        vertical-align: bottom;
        background: rgba(0, 0, 0, 0.6);
        -webkit-transition: all 0.2s ease-in-out 0s;
        -moz-transition: all 0.2s ease-in-out 0s;
        transition: all 0.2s ease-in-out 0s;
        color: white;
        font-size: 13px
    }


    .green {
        color: #28a267 !important
    }

    .red {
        color: #f34b3f !important
    }

    .blue {
        color: #34afbe !important
    }

    .gray {
        color: #959595 !important
    }

    .yellow {
        color: #ffff00 !important
    }

    .orange {
        color: #FFA500 !important
    }

    .label-green {
        background-color: #28a267 !important;
        color: white !important;
        border-color: #28a267
    }

    .label-red {
        background-color: #ef4437 !important;
        color: white !important;
        border-color: #ef4437
    }

    .label-blue {
        background-color: #34afbe !important;
        color: white !important;
        border-color: #34afbe
    }

    .label-pink {
        background-color: #ff7994 !important;
        color: white !important;
        border-color: #ff7994
    }

    .label-gray {
        background-color: #959595 !important;
        color: white !important;
        border-color: #959595
    }

    .label-orange {
        background-color: orange !important;
        color: white !important;
        border-color: orange
    }

    .main-view {
        background-color: #eeeeee;
        /*min-height: 100%;*/
        color: #555555;
        -webkit-transform: translate3d(0, 0, 0)
    }

    .main-view a {
        color: #555555
    }

    .notification-section {
        background-color: white;
        padding: 0 10px;
        border-bottom: 1px solid #dbdbdb
    }

    .notification-section .notice {
        border-top: 1px dotted #eeeeee;
        padding: 8px 0;
        padding-left: 30px;
        line-height: 20px
    }

    .notification-section .notice i {
        display: block;
        float: left;
        margin-left: -30px;
        text-align: center;
        width: 30px
    }
</style>
<div class="ddb-nav-header ng-scope">
    <a class="nav-left-item" href="{php echo $this->createMobileurl('waprestlist', array(), true)}"><i class="fa fa-angle-left"></i></a>
    <div class="header-title ng-binding">{$store['title']}</div>
    <a class="nav-right-item" href="#">
        <div class="operation-button gray"></div>
    </a>
</div>
{if !empty($store['announce'])}
<div class="notification-section" style="margin-top: 45px;">
    <div class="notice">
        <i class="fa fa-volume-up red" style="margin-top:4px;"></i>
        <marquee behavior="alternate" scrollamount="1" scrolldelay="1" class="ng-binding">{$store['announce']}</marquee>
    </div>
</div>
{/if}
<div id="ddb-delivery-branch-index" class="main-view ng-scope" {if empty($store['announce'])}style="margin-top: 45px;"{/if}>
<div class="morelist branch-item ng-scope ">
    <input id="showlan" type="hidden" value="{$store['lng']},{$store['lat']}"/>
    <a class="branch-info " href="{php echo $this->createMobileurl('detail', array('id' => $storeid, 'isdelivery' => $this->_isdelivery), true)}">
        <div class="branch-image">
            <img src="{php echo tomedia($store['logo']);}" style="width: 74px;height: 40px">
        </div>
        <div class="delivery-info" style="padding-right:50px;padding-left:15px;">
            <div class="first-line">
                <div class="comment-level red">
                    <div class="ng-isolate-scope">
                        <?php for($i=0;$i < $store['level']; $i++){ ?>
                        <i class="fa fa-star-o ng-scope" style="font-size:12px;"></i>
                        <?php }?>
                    </div>
                </div>
                <div style="width:100%;position:absolute;top:10px;right:60px;"><div class="distance right ng-binding" id="shopspostion" style="float: right;"></div><img style="width:12px;height:12px;float:right;margin-right:10px;margin-top:3px;" src="../addons/smart_ct/template/images/loc.png"></div>
            </div>
            <div class="second-line">
                <div class="fee ng-binding" style="width:100%;">
                    {if !empty($store['sendingprice'])}
                    <span class="ng-binding ng-scope">￥{$store['sendingprice']}起送</span>
                    <span class="spliter"></span>
                    {/if}
                    {if !empty($store['dispatchprice'])}
                    <span class="ng-binding ng-scope" style="float:right;">配送费￥{$store['dispatchprice']}</span>
                    <span class="spliter"></span>
                    {/if}
                </div>
            </div>
        </div>
        <img src="../addons/smart_ct/template/images/arrow.png" style="position:absolute;top:25px;right:15px;width:12px;height:16px;">
    </a>
</div>
</div>
<div class="center">
    <nav id="navBar">
        <dl>
            {php $flag = false;}
            {loop $category $item}
                <dd categoryid="{$item['id']}" {if $flag!=true}class="active"{/if}>
                    {$item['name']}
                    {if empty($category_arr[$item['id']])}
                    <span style="display:none;"></span>
                    {else}
                    <span style="display:inline-block;">{$category_arr[$item['id']]}</span>
                    {/if}
                </dd>
                {php $flag = true;}
            {/loop}
        </dl>
        <div style="margin-top: 100px;"></div>
    </nav>
    <section id="infoSection">
        <article style="border-top: 0px solid #e7eaeb;">
            <div id="pInfo">
                {loop $list $row}
                <dl dunitname="{$row['unitname']}" dsubcount="{$row['subcount']}" dishid="{$row['id']}" dname="{$row['title']}" dtaste="{$row['taste']}" ddescribe="{$row['description']}" dprice="{$row['productprice']}" dishot="{if $row['subcount']>500}2{else}0{/if}" dspecialprice="{if $row['isspecial']==2}{$row['marketprice']}{/if}" disspecial="{$row['isspecial']}" shopinfo="">
                    <dt><h3>{$row['title']}</h3></dt>
                    <dd>
                        <a href="javascript:void(0)" class="dataIn">
                            <img src="{$_W['attachurl']}{$row['thumb']}" alt="" title="">
                            {if $row['subcount']>500}
                            <span></span>
                            {/if}
                        </a>
                    </dd>
                    <dd>
                        {if $row['marketprice']!=''}
                        <em class="sale"><b>特价</b>{$row['marketprice']}元/{$row['unitname']}<br><del>{$row['productprice']}元/{$row['unitname']}</del></em>
                        {else}
                        <em>{$row['productprice']}元/{$row['unitname']}</em>
                        {/if}
                    </dd>
                    <dd class="dpNum">{$row['subcount']}人点过</dd>
                    <dd class="btn">
                        <button class="minus" style="display:inline-block;"><strong></strong></button>
                        <i style="display: inline-block;">{if !empty($dish_arr[$row['id']])}{$dish_arr[$row['id']]}{else}0{/if}</i>
                        <button class="add"><strong></strong></button>
                        <em class="fixBig fake"></em>
                    </dd>
                </dl>
                {/loop}
                <div style="margin-top: 100px;"></div>
            </div>
        </article>
    </section>
    {php include $this->template('_header');}
    {php include $this->template('_footer');}
</div>
<script type="text/javascript">
    var view_const_dish_SPECIAL_PRICE_YES = '2';
    var view_const_dish_SPECIAL_PRICE_VIP = '3';
    var view_const_dish_HOT_YES = '2';
    function setHeight(){
        var  cHeight;
        cHeight = document.documentElement.clientHeight;
        cHeight = cHeight +"px"
        document.getElementById("navBar").style.height =  cHeight;
        document.getElementById("infoSection").style.height =  cHeight;
    }
    //ajax处理
    //配合_doAjax方法使用
    function doSelect(){
        var dds = _qAll('#navBar dd');
        var aa=0, bb;
        var article = _q("#infoSection article");
        _forEach(dds, function(ele, idx, dds) {
            dds[idx].onclick = function(){
                _q('.active').className = null;
                this.className = "active";
                var div = document.getElementById("pInfo");

                div.innerHTML = '';
                var params = {
                    'action' : 'getDishList',
                    'categoryid' : this.getAttribute('categoryId')
                };

                var url = "{php echo $this->createMobileUrl('GetDishList', array('storeid' => $storeid, 'from_user' => $from_user), true)}";
                //alert(url);
                _doAjax(url, 'GET', params, function(ret) {
                    //alert(ret['message']['debug']);
                    var dishList = ret['message']['data'];
                    var categoryId = ret['message']['categoryid'];
                    var str = '';
                    var rnd = Math.random();

                    for(key in dishList) {
                        //alert(key);
                        var dish = dishList[key];
//                        if (dish.dIsSpecial == view_const_dish_SPECIAL_PRICE_YES) {
//                            var priceHtml = "<em class='sale'><b>特价</b>"+dish['dSpecialPrice']+"元/"+dish['unitname']+"<br/><del>"+dish['dPrice']+"元/"+dish['unitname']+"</del></em>";
//                        } else if (dish.dIsSpecial == view_const_dish_SPECIAL_PRICE_VIP) {
//                            var priceHtml = "<em><b class='vip'>会员</b>"+dish['dSpecialPrice']+"元/"+dish['unitname']+"<br/><del>"+dish['dPrice']+"元/"+dish['unitname']+"</del></em>";
//                        }

                        if (dish['dSpecialPrice'] != '') {
                            var priceHtml = "<em class='sale'><b>特价</b>"+dish['dSpecialPrice']+"元/"+dish['unitname']+"<br/><del>"+dish['dPrice']+"元/"+dish['unitname']+"</del></em>";
                        } else {
                            var priceHtml = "<em>"+dish['dPrice']+"元/"+dish['unitname']+"</em>";
                        }
                        if (dish.dIsHot == view_const_dish_HOT_YES) {
                            var hotHtml = '<span></span>';
                        } else {
                            var hotHtml = '';
                        }
                        if (dish['dSubCount']) {
                            var dSubCountHtml = dish['dSubCount'] + '人点过';
                        } else {
                            var dSubCountHtml = '';
                        }
                        var attrList = " dUnitName='"+dish['unitname']+"' dSubCount='"+dish['dSubCount']+"' dishid='"+dish['id']+"' dName='"+dish['title']+"' dTaste='"+dish['dTaste']+"' dDescribe='"+dish['dDescribe']+"' dPrice='"+dish['dPrice']+"' dIsHot='"+dish['dIsHot']+"' dSpecialPrice='"+dish['dSpecialPrice']+"' dIsSpecial='"+dish['dIsSpecial']+"' ";
                        str += "<dl shopInfo='' "+attrList+"'><dt><h3>"+dish['title']+"</h3></dt><dd><a href='javascript:void(0)' class='dataIn'><img src='{$_W['attachurl']}" + dish['thumb'] + "?rnd="+rnd+"' alt='' title='' />"+hotHtml+"</a></dd><dd>"+priceHtml+"</dd><dd class='dpNum'>"+dSubCountHtml+"</dd><dd class='btn'><button class='minus'><strong></strong></button><i>"+dish['total']+"</i><button class='add'><strong></strong></button><em class='fixBig fake'></em></dd></dl>";
                    }
                    str += '<div style="margin-top: 60px;"></div>';

                    if (_q('.active').getAttribute('categoryId') == categoryId) {
                        div.innerHTML = str;
                        _q('#infoSection').scrollTop = 0;
                        doSelectBtn();
                        showPicInfo();
                    }
                });
            }
        });
    }

    //选择商品按钮样式
    function doSelectBtn(){
        var btn = _qAll("article dl .btn");
        var btnIndex = 0,btnLength = btn.length;

        // countDish();
        for(btnIndex;btnIndex<btnLength;btnIndex++){
            var countNumText=parseInt(btn[btnIndex].children[1].innerHTML),
                btnAdd=btn[btnIndex].children[2],
                btnMin=btn[btnIndex].children[0];

            btnShowHide(countNumText,btn[btnIndex], false);

            var iTimeout,iInterval, originalNum,
                beforeRemoveDish=false,
                beforeAddDish=false,
                needRemoveNotify=false; //是否需要删除提醒

            btnAdd.addEventListener(_movestartEvt,function(){
                beforeRemoveDish = false;
                var _self = this;
                originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
                countNumText =  originalNum +1;
                var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');
                ///debug
                if (countNumText == 1) {
                    if (shopInfo) {
                        _self.parentNode.children[1].innerHTML = 0;
                        beforeAddDish = true;
                        return;
                    } else {
                        _self.parentNode.children[1].innerHTML = 1;
                        btnShowHide(1, _self.parentNode);
                    }
                } else {
                    _self.parentNode.children[1].innerHTML = countNumText;
                    btnShowHide(countNumText,_self.parentNode);
                    iTimeout = setTimeout(function(){
                        // console.log(_self);
                        iInterval = setInterval(function(){
                            countNumText++;
                            _self.parentNode.children[1].innerHTML = countNumText;
                            // 变化打数字
                            _removeClass(_self.parentNode.children[3],'fake');
                            _self.parentNode.children[3].innerHTML = countNumText
                        },100)
                    },1000)
                }
            })

            btnAdd.addEventListener(_moveendEvt,function(){//add
                clearTimeout(iTimeout);
                clearInterval(iInterval);
                hideBigFont();
                var _self = this;
                var countNumText =  parseInt(_self.parentNode.children[1].innerHTML, 10);
                var dishid = _self.parentNode.parentNode.getAttribute('dishid');
                var shopInfo =_self.parentNode.parentNode.getAttribute('shopInfo');

                var price=_self.parentNode.parentNode.getAttribute('dspecialprice');
                if(price==""){
                    var dprice=_self.parentNode.parentNode.getAttribute('dprice');
                    price= dprice;
                }

                if (beforeAddDish) {
                    //alert('debug');
                    setTimeout(function(){
                        MDialog.confirm(
                            '', shopInfo, null,
                            '确定', function(){
                                _self.parentNode.children[1].innerHTML = 1;
                                btnShowHide(1, _self.parentNode);
                                ajaxDishReset(dishid, 1, function(){}, function() {
                                    _self.parentNode.children[1].innerHTML = originalNum;                                                                 btnShowHide(originalNum, _self.parentNode);
                                });
                        }, null,
                            '取消', function(){}, null,
                            null, true, true
                        );
                    }, 500);
                    beforeAddDish = false;
                } else {
                    var totalprice = parseFloat(_q("#totalprice").value)+parseFloat(price);
                    var totalcount = parseInt(_q("#totalcount").value)+1;
                    totalprice = totalprice.toFixed(1);

                    _q("#totalprice").value = totalprice;
                    _q("#totalpriceshow").innerHTML = totalprice;
                    _q("#totalcount").value = totalcount;
                    _q("#totalcountshow").innerHTML = totalcount;

                    ajaxDishReset(dishid, countNumText, function(){}, function() {
                        _self.parentNode.children[1].innerHTML = originalNum;
                        btnShowHide(originalNum, _self.parentNode);
                    });
                }
            })

            btnMin.addEventListener(_movestartEvt,function(){
                var _self = this;
                originalNum = parseInt(_self.parentNode.children[1].innerHTML, 10);
                countNumText =  originalNum -1;
                if(countNumText <= 0 ){
                    _self.parentNode.children[1].innerHTML = 1;
                    beforeRemoveDish = true;
                    return;
                } else {
                    _self.parentNode.children[1].innerHTML = countNumText;
                    iTimeout = setTimeout(function(){
                        iInterval = setInterval(function(){
                            countNumText--;
                            if(countNumText <= 0){
                                clearInterval(iInterval);
                                _self.parentNode.children[1].innerHTML = 1;
                                beforeRemoveDish = true;
                                return;
                            } else {
                                _self.parentNode.children[1].innerHTML = countNumText;
                                btnShowHide(countNumText,_self.parentNode);
                            }
                            // 字体放大显示
                            _removeClass(_self.parentNode.children[3],'fake');
                            _self.parentNode.children[3].innerHTML = countNumText
                        },100)
                    },1000)
                }
            })

            btnMin.addEventListener(_moveendEvt,function(){
                clearTimeout(iTimeout);
                clearInterval(iInterval);
                hideBigFont();
                var _self = this;
                var countNumText =  parseInt(_self.parentNode.children[1].innerHTML, 10);
                var dishid = _self.parentNode.parentNode.getAttribute('dishid');
                var dName = _self.parentNode.parentNode.getAttribute('dName');

                var price = _self.parentNode.parentNode.getAttribute('dspecialprice');
                if(price == ""){
                    var dspecialprice=_self.parentNode.parentNode.getAttribute('dprice');
                    price= dspecialprice;
                }

                var totalprice = parseFloat(_q("#totalprice").value)-parseFloat(price);
                var totalcount = parseInt(_q("#totalcount").value)-1;
                totalprice = totalprice.toFixed(1);

                _q("#totalprice").value = totalprice;
                _q("#totalpriceshow").innerHTML = totalprice;
                _q("#totalcount").value = totalcount;
                _q("#totalcountshow").innerHTML = totalcount;

                if (beforeRemoveDish) {
                    if (needRemoveNotify) {
                        setTimeout(function(){
                            MDialog.confirm(
                                '', '是否删除'+dName+'？', null,
                                '确定', function(){
                                    _self.parentNode.children[1].innerHTML = 0;
                                    btnShowHide(0, _self.parentNode);
                                    //alert('needRemoveNotify');//debug
                                    ajaxDishRemove(dishid, function(){}, function() {
                                        _self.parentNode.children[1].innerHTML = originalNum;
                                        btnShowHide(originalNum, _self.parentNode);
                                    });
                                }, null,
                                '取消', function(){
                                    _self.parentNode.children[1].innerHTML = originalNum;
                                    btnShowHide(originalNum, _self.parentNode);
                                }, null,
                                null, true, true
                            );
                        }, 500);
                        beforeRemoveDish = false;
                    } else {
                        //alert('not_needRemoveNotify');//debug
                        _self.parentNode.children[1].innerHTML = 0;
                        btnShowHide(0, _self.parentNode);
                        ajaxDishRemove(dishid, function(){}, function() {
                            _self.parentNode.children[1].innerHTML = originalNum;
                            btnShowHide(originalNum, _self.parentNode);
                        });
                        beforeRemoveDish = false;
                    }
                } else {
                    ajaxDishReset(dishid, countNumText, function(){}, function() {
                        _self.parentNode.children[1].innerHTML = originalNum;
                        btnShowHide(originalNum, _self.parentNode);
                    });
                }
            }) // btnMin.addEventListener
        }

        //更新分类商品数量
        function ajaxDishReset(dishid, o2uNum, successCallback, errorCallback) {
            var params = {
                'dishid' : dishid,
                'o2uNum' : o2uNum
            };
            //alert('dishid:'+dishid+';o2uNum:'+o2uNum);
            //debug
            var url = "{php echo $this->createMobileUrl('UpdateDishNumOfCategory', array('storeid' => $storeid, 'from_user' => $from_user), true)}";

            //successCallback();
            _doAjax(url, 'POST', params, function(ret) {
                //alert(ret['message']['msg']);return;

                if (ret['message']['code'] != 0) {
                    errorCallback();
                    alert(ret['message']['msg']);
                    return;
                } else {
                    successCallback();
                }
                successCallback();
            });
        } // ajaxDishReset

        function ajaxDishRemove(dishid, successCallback, errorCallback) {
            var params = {
                'dishid' : dishid,
                'action' : 'remove'
            };

            var url = "{php echo $this->createMobileUrl('RemoveDishNumOfCategory', array('storeid' => $storeid, 'from_user' => $from_user), true)}";

            _doAjax(url, 'POST', params, function(ret) {
                if (ret['message']['code']!= 0) {
                    errorCallback();
                    alert(ret['message']['msg']);
                    return;
                } else {
                    successCallback();
                }
            });
        } // ajaxDishRemove
    } // doSelectBtn

    function hideBigFont(){
        var _arr = _qAll(".fixBig");
        _forEach(_arr,function(ele,idx,_arr){
            _addClass(ele,'fake');
        })
    }

    function btnShowHide(num,btns, isCountDish){

        if (isCountDish !== false) {
            countDish();
        }

        if (num <= 0) {
            btns.children[0].style.display ="none";
            btns.children[1].style.display ="none";
        } else {
            btns.children[0].style.display ="inline-block";
            btns.children[1].style.display ="inline-block";
        };
    }

    function countDish(){
        var countTotle = 0,countdish;
        var dishNum = _qAll("#page_allMenu section article dl .btn i");
        _forEach(dishNum,function(ele,idx,dishNum){
            countdish = parseInt(ele.innerHTML);
            if(countdish>0){
                countTotle++;
            }
        });

        if(countTotle != 0){
            _q("#page_allMenu nav dl dd.active span").innerHTML = countTotle;
            _q("#page_allMenu nav dl dd.active span").style.display='block';
        }else{
            _q("#page_allMenu nav dl dd.active span").style.display='none';
        }
    }

    //点击促发弹层事件
    function showPicInfo(){
        var links = _qAll(".dataIn"), i=0;
        for(i;i<links.length;i++){
            links[i].onclick=function(event){
                event.stopPropagation();
                // dl
                var parentDl = this.parentNode.parentNode;
                var childImg = this.childNodes[0]
                if(childImg.nodeType == 3){
                    childImg = this.childNodes[1];
                }

                var dSpecialPrice = parentDl.getAttribute('dSpecialPrice');

                if (dSpecialPrice != '') {
                    dSpecialPrice = parentDl.getAttribute('dSpecialPrice') + '元/' + parentDl.getAttribute('dunitName');
                }

                popPic(childImg.src,
                        parentDl.getAttribute('dname'),
                        parentDl.getAttribute('dprice') + '元/' + parentDl.getAttribute('dunitName'),
                        parentDl.getAttribute('dIsSpecial'),
                        dSpecialPrice,
                        parentDl.getAttribute('dsubCount'),
                        parentDl.getAttribute('dtaste'),
                        parentDl.getAttribute('ddescribe'),
                        parentDl.getAttribute('dishot')
                        );
            }
        }
    }
    //后台可自行扩展参数
    //调用自定义弹层
    function popPic(imgUrl,title,price, isSpecial, specialPrice, people,teast,assess,isHot){
        var _title = title,
            _price = price,
            _people = people,
            _teast = teast,
            _assess = assess;

        var hotHtml = '';
        if (isHot == view_const_dish_HOT_YES) {
            hotHtml = '<b></b>';
        }
            _tmpHtml = "<div class='content'>"+hotHtml+"<img src='"+imgUrl+"' alt='' title=''><h2>"+_title+"<br>";


             if (specialPrice != '') {
                 _tmpHtml += "<i>"+specialPrice+"</i><del>"+_price+"</del>";
             } else {
                 _tmpHtml += "<i>"+_price+"</i>";
             }

            if (_people) {
                _tmpHtml += "<span>"+_people+"人点过</span>";
            }
            _tmpHtml += "</h2>";

            if (_teast) {
                _tmpHtml += "<h3>口味："+_teast+"</h3>";
            }

            if (_assess) {
                _tmpHtml += "<p>"+_assess+"</p>";
            }

            _tmpHtml += '</div>';
            MDialog.popupCustom(_tmpHtml,true, function(){}, true);
    }

    // 获取各个分类被选中商品的数量
    function getDishNumOfCategory() {
        var params = {
        };
        _doAjax("{php echo $this->createMobileUrl('GetDishNumOfCategory', array('storeid' => $storeid, 'from_user' => $from_user), true)}", 'POST', params, function(ret) {
            for(var i in ret.message.data) {
                var val = ret['message']['data'][i];
                if (val > 0) {
                    //debug
                    _q('[categoryId="'+i+'"] span').innerHTML = val;
                    _q('[categoryId="'+i+'"] span').style.display='block';
                } else {
                    _q('[categoryId="'+i+'"] span').style.display='none';
                }
            }
        });
    }

    _onPageLoaded(function(){
        setHeight();
        doSelect();
        doSelectBtn();
        showPicInfo();
        getDishNumOfCategory();
        if(_isIOS){
            _q("#page_allMenu section article").style.overflowY ="scroll";
            _q("#page_allMenu section article").style.minHeight ="85%";
            _q("#page_allMenu section article").style.marginBottom="15px";
        }
    })
    window.addEventListener('orientationchange', function(){
        setHeight();
    })
</script>
</body>
</html>